package utils;

import org.junit.Test;

public class MoneyTransfromUtils {

    public static String changeYuan2Fen(String amount){
        String currency =  amount.replaceAll("\\$|\\￥|\\,", "");  //处理包含, ￥ 或者$的金额
        int index = currency.indexOf(".");
        int length = currency.length();
        Long amLong = 0L;
        if(index == -1){
            amLong = Long.valueOf(currency+"00");
        }else if(length - index >= 3){
            amLong = Long.valueOf((currency.substring(0, index+3)).replace(".", ""));
        }else if(length - index == 2){
            amLong = Long.valueOf((currency.substring(0, index+2)).replace(".", "")+0);
        }else{
            amLong = Long.valueOf((currency.substring(0, index+1)).replace(".", "")+"00");
        }
        return amLong.toString();
    }

    //排除前六位和后面四位打*
    public static String star(String s){
        return s.replaceAll("(?<=\\w{6})\\w(?=\\w{4})" , "*");
    }

    @Test
    public void changeYuan2FenTest(String[] args) {
        String a = "0.8";
        System.out.println(changeYuan2Fen(a));
    }

}
